import axios from "@/utils/http";

const blog = {
  // 首页博客数据
  getIndexBlog(params) {
    return axios.post("/api/blogIndex", params);
  },

  // 博客详情
  getBlog(blogId) {
    return axios.get(`/api/blogs/${blogId}`);
  },

  // 所有分类下的博客
  getCategoryBlog() {
    return axios.get("/api/category/blog");
  },

  // 创建博客
  create(params) {
    return axios.post("/api/blogs", params);
  },

  // 更新博客
  update(params) {
    const blogId = params.blogId;
    return axios.put(`/api/blogs/${blogId}`, params);
  },

  // 给博客设置分类
  setCategory(params) {
    const { blogId, categoryId } = params;
    return axios.patch(
      `/api/blog-category/setCategory?categoryId=${categoryId}&blogId=${blogId}`
    );
  },

  // 给博客设置标签
  setTags(params) {
    return axios.post("/api/blog-tag/setTags", params);
  },

  // 删除博客
  deleteBlog(blogId) {
    return axios.delete(`/api/blogs/${blogId}`);
  }
};

export default blog;
